﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using OSIRIS.Service;

namespace OSIRIS.Service.Host
{
    /// <summary>
    /// The Program class is used to house several methods that start
    /// and stop the service, as well as the Main() method.
    /// </summary>
    class Program
    {
        /// <summary>
        /// The ServiceHost instance that is used to host the OSIRIS
        /// service.
        /// </summary>
        internal static ServiceHost serviceHost = null;

        /// <summary>
        /// Start the service.
        /// </summary>
        internal static void StartService()
        {
            /* create new ServiceHost */
            serviceHost = new ServiceHost(typeof(OSIRISService));

            /* start listening */
            serviceHost.Open();
        }

        /// <summary>
        /// Stop the service.
        /// </summary>
        internal static void StopService()
        {
            /* if the service was not stopped yet */
            if (serviceHost.State != CommunicationState.Closed)
            {
                /* stop listening */
                serviceHost.Close();
            }
        }

        /// <summary>
        /// Entry point of application.
        /// </summary>
        /// <param name="args">Command-line arguments</param>
        static void Main(string[] args)
        {
            /* start the service */
            StartService();

            /* write output to console */
            Console.WriteLine("Web service for OSIRIS started.");
            Console.WriteLine("Press enter to stop the service.");
            Console.ReadLine();

            /* stop the service */
            StopService();
        }
    }
}
